<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<style type="text/css">
			.topic_nickname {
				font-size: 14px;
				color: #0000FF;
			}
			.ellipsis-public {	/*1溢出*/
				width: 100%;
				height: 20px;
				line-height: 20px;
			    overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 1;	
				-webkit-box-orient: vertical;
			}
		</style>
	</head>

	<body>
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<ul class="mui-table-view" id="wd_msg_ul">
				</ul>
				<ul class="mui-table-view" id="yd_msg_ul">
				</ul>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/zepto.min.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript" charset="utf-8">
			var index;
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					}
				}
			});
			mui.plusReady(function(){
				//获得主页面webview引用；
				index = plus.webview.currentWebview().opener();
				if(isLogin()) {
					mui.fire(index, "hideLogout");
					mui.fire(index, "hideCreateTopic");
				}
				initData();
			});
			function initData() {
				mui.ajax({
					type: "post",
					url: _baseUrl + "/api/notification",
					data: {
						token: plus.storage.getItem(_user_token)
					},
					async: true,
					dataType: "json",
					success: function(data) {
						var oldMessages = data.detail.oldMessages;
						var notifications = data.detail.notifications;
						
						var wd_msg_ul = $("#wd_msg_ul");
						wd_msg_ul.html('<li class="mui-table-view-divider">未读消息</li>');
						mui.each(notifications, function(index, _data){
							var html = '<li class="mui-table-view-cell"><a href="javascript:topic_detail(\''+_data.tid+'\')">'+
										'<span class="topic_nickname">'+_data.nickname+'</span> '+
										'<span>'+_data.message+'</span> '+
										'<span class="topic_nickname">'+_data.title+'</span>'+
										'</a></li>';
							wd_msg_ul.append(html);
						});
						var yd_msg_ul = $("#yd_msg_ul");
						yd_msg_ul.html('<li class="mui-table-view-divider">已读消息</li>');
						mui.each(oldMessages, function(index, _data){
							var html = '<li class="mui-table-view-cell"><a href="javascript:topic_detail(\''+_data.tid+'\')">'+
										'<span class="topic_nickname">'+_data.nickname+'</span> '+
										'<span>'+_data.message+'</span> '+
										'<span class="topic_nickname">'+_data.title+'</span>'+
										'</a></li>';
							yd_msg_ul.append(html);
						});
						mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					}
				});
			}
			
			function pulldownRefresh() {
				initData();
			}
		</script>
	</body>

</html>